#!/usr/bin/perl
#save_cifs.cgi

require './protocolman-lib.pl';

&ReadParse();
if ($in{'serverdescin'} =~ /[\#\;]/)
{
	&nas_syslog("protocolman", "naslog_warning", 32004, "Server description invalid!");
	&error($text{'desc_invalid'});	
}	
&foreign_require("samba", "samba-lib.pl");
%econfig = &foreign_config("samba");
&lock_file($econfig{'smb_conf'});
$global = &foreign_call("samba", "get_share", "global");

&foreign_call("samba","setval","server string", $in{'serverdescin'}, "");
&foreign_call("samba","setval","encrypt passwords", "yes", "");
&foreign_call("samba","setval","null passwords", "no", "");

if (($in{'securityrdn'} ne $in{'oldsecurity'})&&($in{'securityrdn'} !~ /domain/))
{
	&foreign_call("samba","setval","security", $in{'securityrdn'}, "");
}
#$mapfile = &foreign_call("samba", "getval", "username map");
#if ($in{'optionrdn'} =~ /0/)
#{
&foreign_call("samba", "delval", "username map");
#}
#else
#{
#	if (!$mapfile)
#	{
#		$econfig{'smb_conf'} =~ /^(.*)\/[^\/]+$/;
#		$mapfile = "$1/user.map";
#	}
#	&foreign_call("samba", "setval", "username map", $mapfile);
#	@maparray = split(":", $in{'mapcache'});
#	foreach $d (@maparray) {
#		$d =~ /^(.*)=(.*)$/;
#		$t1 =$1;$t2 = $2;
#		if ($t1 =~ /\S/ && $t2 =~ /\S/) {
#			if ($t2 =~ /\s/) {
#				push(@umap, $t1."=\"".
#					    $t2."\"");
#			}
#			else {
#				push(@umap, $t1."=".
#					    $t2);
#			}
#		}
#	}
#	&lock_file($mapfile);
#	open(UMAP, "> $mapfile");
#	foreach $line (@umap) {
#		print UMAP "$line\n";
#		}
#	close(UMAP);
#	&unlock_file($mapfile);
#}
&foreign_call("samba","setval","client code page", $in{'codesel'});
if ($global)
{
	&foreign_call("samba","modify_share", "global", "global");
}
else
{
	&foreign_call("samba","create_share", "global");
}
&unlock_file($econfig{'smb_conf'});
`$config{'cifs_service'} reload`;
#&lock_file("$config_directory/samba/config");
#foreach $s ("add", "change", "delete") {
#	$econfig{"sync_$s"} = 1;
#	}
#&write_file("$config_directory/samba/config", \%econfig);
#&unlock_file("$config_directory/samba/config");
&nas_syslog("protocolman", "naslog_info", 32003, "Change CIFS protocol settings success!");
&redirect("index.cgi");
